lionsApp
    .controller('detailCtrl', ['$scope', '$state', '$rootScope', 'lionsHttp', 'myFunction', '$timeout', '$sce', function ($scope, $state, $rootScope, lionsHttp, myFunction, $timeout, $sce) {
        $scope.auctionId = myFunction.getUrlParam(location.href).auctionId
        lionsHttp.checkBind({}, {}, function (data) {
            if(!data.data){
                $state.go('identity')
            }
        })
        lionsHttp.detail({}, {code: $scope.auctionId}, function (data) {
            $scope.detailInfo = data.data.goods
            $scope.intro = $sce.trustAsHtml($scope.detailInfo.demo)
            $scope.detailImgs = $scope.detailInfo.img.split(';')
            $scope.remainTimes = data.data.time
            $scope.swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable: true,
                observer: true
            })
            $scope.priceList = data.data.listPrice
        })
        // $scope.qrcode = new QRCode('qrcode', {
        //     text: location.href,
        //     width: 150,
        //     height: 150,
        //     colorDark : '#000000',
        //     colorLight : '#ffffff',
        //     correctLevel : QRCode.CorrectLevel.H
        // })
        $scope.amountPlus = function () {
            // $scope.detailInfo.maxAmount = parseInt($scope.detailInfo.maxAmount + Number($scope.detailInfo.maxAmount) * 0.1)
            $scope.detailInfo.maxAmount += 100
        }
        $scope.sendAuction = function () {
            $scope.error = '出价中，请等待...'
            if(!$scope.btnDisabled){
                $scope.btnDisabled = true
                lionsHttp.createAuction({}, {
                    goodsCode: $scope.detailInfo.code,
                    amount: $scope.detailInfo.maxAmount
                }, function (data) {
                    $scope.btnDisabled = false
                    if(data.statusCode == 0){
                        $scope.error = '恭喜您, 出价成功'
                        location.reload()
                    }else{
                        $scope.error = data.statusMessage
                        $scope.timer = $timeout(
                            function () {
                                $scope.error = false
                            },
                            2000
                        )
                    }
                })
            }
        }
    }])